/*****************************************************************************
State of Aadhaar Survey 2017-2018

Title: 5_Mobile_pub.do
Author: IDinsight
Contact: stateofaadhaar@idinsight.org
Date: 29 August 2018
Data: "SOA2018_nonroster_cleaned_gen.dta"
User-written commands: estout (ssc install estout if not installed)
Description: 	This .do file conducts analysis for the Mobile section and
				produces output tables in "5_Mobile.rtf".

Contents:
	
	1. Analysis using non roster data
		- Survey set up
		- Tabulations / Proportions / Means
		- Regressions / Hypothesis tests
	
Missing data code:
	.r = refused
	.d = don't know	
*****************************************************************************/

	
* Setting up
	
	version 14
	capture log close
	clear all
	mac drop _all
	set more off

	* Please replace "..." below with the correct file path on your computer
	if "`c(os)'"=="MacOSX"{
		global dir "/Users/`c(username)'/.../SOA2018_data_release/"
		}
	else{
		global dir "C:/Users/`c(username)'/.../SOA2018_data_release/"
		}		

		
/*****************************************************************************
1. Analysis using non roster data
*****************************************************************************/

	*** Survey set up

		cd "${dir}/Data_sets/"
		use "SOA2018_nonroster_cleaned_gen.dta", clear

		drop hh_id
		rename master_key hh_id 
		svyset district_id [pweight=weight_resp_adj] || AC_id || ps_id || hh_id || _n
		cd "${dir}/Output_tables/"
		

	***  Tabulations / Proportions / Means
			
		/*****************************************************************************
		5.1.1: Percentage of respondents who own a mobile phone
		*****************************************************************************/
		
			eststo clear
			eststo: estpost svy: tab mobile_fm1, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (mobile_fm1 ==.d | mobile_fm1 ==.r) 
			loc miss = r(N)
			count if (mobile_fm1 ==.e) 
			loc er = r(N)
			estadd scalar missing  = `miss'
			estadd scalar er  = `er'
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab mobile_fm1 if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (mobile_fm1 ==.d | mobile_fm1 ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (mobile_fm1 ==.e) & state == `i'
				estadd scalar er  = r(N)
				}
				
			esttab using "5_Mobile.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 5.1.1 Percentage of respondents who own a mobile phone") ///	
				nostar ///
				nonumbers ///
				mtitles("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates.") ///
				replace	
			eststo clear
			
			
		/*****************************************************************************
		5.1.2: Percentage of respondents who got their SIM cards before/after Sep 2016 among those who have a mobile phone
		*****************************************************************************/
		
			eststo: estpost svy: tab pre_ekyc if mobile_fm1==1, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (pre_ekyc ==.m) & mobile_fm1==1
			loc miss = r(N)
			count if (pre_ekyc ==.e) & mobile_fm1==1
			loc er = r(N)
			estadd scalar missing  = `miss'
			estadd scalar er  = `er'
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab pre_ekyc if state == `i' & mobile_fm1==1, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (pre_ekyc ==.m) & state == `i' & mobile_fm1==1
				estadd scalar missing  = r(N)
				count if (pre_ekyc ==.e) & state == `i' & mobile_fm1==1
				estadd scalar er  = r(N)
				}
				
			esttab using "5_Mobile.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 5.1.2 Percentage of respondents who got their SIM card before/after Sep 2016 among those who have a mobile phone") ///	
				nostar ///
				nonumbers ///
				mtitles("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates." ///
				"DoT and TRAI allowed the usage of e-KYC for mobile SIM cards in mid-August 2016. Here we have broken down our respondents into those who obtained a SIM card in/after September 2016 and those who obtained a SIM card before September 2016.") ///
				append	
			eststo clear
			
			
		/*****************************************************************************
		5.2: Percentage of respondents by how they used Aadhaar for mobile SIM (among those who have a mobile phone and those who got their SIM card in/after Sep 2016)
		*****************************************************************************/
		
			eststo clear
			
			eststo: estpost svy: tab ad_mobilesimhow if pre_ekyc==0, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (ad_mobilesimhow ==.d | ad_mobilesimhow ==.r) & pre_ekyc==0
			loc miss = r(N)
			count if (ad_mobilesimhow ==.e)  & pre_ekyc==0
			loc er = r(N)
			estadd scalar missing  = `miss'
			estadd scalar er  = `er'
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab ad_mobilesimhow if state == `i' & pre_ekyc==0, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (ad_mobilesimhow ==.d | ad_mobilesimhow ==.r) & state == `i' & pre_ekyc==0
				estadd scalar missing  = r(N)
				count if (ad_mobilesimhow ==.e) & state == `i' & pre_ekyc==0
				estadd scalar er  = r(N)
				}
			esttab using "5_Mobile.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 5.2 How respondents used Aadhaar for mobile SIM card purchases (among those who got their SIM card in/after Sep 2016; numbers in percentage)") ///	
				nostar ///
				coeflabels(0 "Did not use Aadhaar" 1 "Used Aadhaar as an identification document" 2 "Used Aadhaar e-KYC") ///
				nonumbers ///
				mtitles("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates." ///
				"DoT and TRAI allowed the usage of e-KYC for mobile SIM cards in mid-August 2016, therefore we conduct this analysis for those who received their SIM cards in/after Sep 2016.") ///
				append	
			eststo clear
			
			
		/*****************************************************************************
		5.3: Percentage of respondents who have their SIM activated in 1 day and usage of e-KYC (among those who have a mobile phone, those who got their SIM card , and those who DID NOT use e-KYC/who DID use e-KYC *
		*****************************************************************************/
		
			eststo clear
			
			eststo: estpost svy: tab simactivatecategories1 if ad_mobilesimhow3==0 & pre_ekyc==0, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (simactivatecategories1 ==.d | simactivatecategories1 ==.r) & ad_mobilesimhow3==0 & pre_ekyc==0
			loc miss = r(N)
			count if (simactivatecategories1 ==.e) & ad_mobilesimhow3==0 & pre_ekyc==0
			loc er = r(N)
			estadd scalar missing  = `miss'
			estadd scalar er  = `er'
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab simactivatecategories1 if state == `i' & ad_mobilesimhow3==0 & pre_ekyc==0, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (simactivatecategories1 ==.d | simactivatecategories1 ==.r) & state == `i' & ad_mobilesimhow3==0 & pre_ekyc==0
				estadd scalar missing  = r(N)
				count if (simactivatecategories1 ==.e) & state == `i' & ad_mobilesimhow3==0 & pre_ekyc==0
				estadd scalar er  = r(N)
				}
			esttab using "5_Mobile.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 5.3.1 Percentage of respondents who had their SIM card activated in 1 day, among those who did not use e-KYC (and have a mobile phone, and got their SIM card in/after Sep 2016)") ///	
				nostar ///
				nonumbers ///
				mtitles("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates.") ///
				append
			eststo clear
			
			
			eststo: estpost svy: tab simactivatecategories1 if ad_mobilesimhow3==1 & pre_ekyc==0, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (simactivatecategories1 ==.d | simactivatecategories1 ==.r) & ad_mobilesimhow3==1 & pre_ekyc==0
			loc miss = r(N)
			count if (simactivatecategories1 ==.e) & ad_mobilesimhow3==1 & pre_ekyc==0
			loc er = r(N)
			estadd scalar missing  = `miss'
			estadd scalar er  = `er'
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab simactivatecategories1 if state == `i' & ad_mobilesimhow3==1 & pre_ekyc==0, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (simactivatecategories1 ==.d | simactivatecategories1 ==.r) & state == `i' & ad_mobilesimhow3==1 & pre_ekyc==0
				estadd scalar missing  = r(N)
				count if (simactivatecategories1 ==.e) & state == `i' & ad_mobilesimhow3==1 & pre_ekyc==0
				estadd scalar er  = r(N)
				}
			esttab using "5_Mobile.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 5.3.2 Percentage of respondents who had their SIM card activated in 1 day, among those who used e-KYC (and have a mobile phone, and got their SIM card in/after Sep 2016)") ///	
				nostar ///
				nonumbers ///
				mtitles("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates.") ///
				append
			eststo clear
			
		
		/*****************************************************************************
		5.4: Percentage of respondents by whether they have seeded their mobile SIMs with Aadhaar (among those who have a mobile phone)
		*****************************************************************************/
		
			eststo clear
			eststo: estpost svy: tab mobile_aadhaar, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (mobile_aadhaar ==.d | mobile_aadhaar ==.r) 
			loc miss = r(N)
			count if (mobile_aadhaar ==.e)
			loc er = r(N)
			estadd scalar missing  = `miss'
			estadd scalar er  = `er'
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab mobile_aadhaar if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (mobile_aadhaar ==.d | mobile_aadhaar ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (mobile_aadhaar ==.e) & state == `i'
				estadd scalar er  = r(N)
				}
		
			esttab using "5_Mobile.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 5.4 Percentage of respondents who have seeded their mobile SIM card to Aadhaar (among those who have a mobile phone)") ///	
				nostar ///
				nonumbers ///
				mtitles("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates.") ///
				append	
			eststo clear
			
			
		/*****************************************************************************
		5.5: Percentage of respondents by SIM carrier (among those who used e-KYC to get their SIM cards and those who got their SIM card ) *
		*****************************************************************************/
		
			* Pooled
				eststo clear
				eststo: estpost svy: tab simcarrier if pre_ekyc==0 & ad_mobilesimhow3==1, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (simcarrier ==.d | simcarrier ==.r) & pre_ekyc==0 & ad_mobilesimhow3==1
				estadd scalar missing  = r(N)
				count if (simcarrier ==.e) & pre_ekyc==0 & ad_mobilesimhow3==1
				estadd scalar er  = r(N)
				
				esttab using "5_Mobile.rtf", ///
					compress ///
					collabels(none) ///
					eqlabels(none) ///
					label ///
					modelwidth(0) ///
					incelldelimiter(-) ///
					cells(b(fmt(1)) "cil & ciu") ///
					mtitles ("All three states")	///
					title ("Table 5.5.1 Mobile SIM carriers (among those who used e-KYC to get their SIM card and those who got their SIM card in/after Sep 2016; numbers in percentage) [All three states]") ///	
					nostar ///
					nonumbers ///
					nogaps ///
					stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
					nonotes ///
					addnotes("Notes: 95% confidence intervals are under point estimates.") ///
					append	
				eststo clear
			
			
			* By state
			tokenize `" "Andhra Pradesh" "Rajasthan" "West Bengal" "'
			forvalues i = 1/3 {
				eststo clear
				display `i' 
				eststo: estpost svy: tab simcarrier if state == `i' & pre_ekyc==0 & ad_mobilesimhow3==1, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (simcarrier ==.d | simcarrier ==.r) & state == `i' & pre_ekyc==0 & ad_mobilesimhow3==1
				estadd scalar missing  = r(N)
				count if (simcarrier ==.e) & state == `i' & pre_ekyc==0 & ad_mobilesimhow3==1
				estadd scalar er  = r(N)
				local k = `i' + 1
				
				esttab using "5_Mobile.rtf", ///
					compress ///
					collabels(none) ///
					eqlabels(none) ///
					label ///
					modelwidth(0) ///
					incelldelimiter(-) ///
					cells(b(fmt(1)) "cil & ciu") ///
					mtitles ("``i++''")	///
					title ("Table 5.5.`k' Mobile SIM carriers (among those who used e-KYC to get their SIM card and those who got their SIM card in/after Sep 2016; numbers in percentage) [State: ``i++'']") ///	
					nostar ///
					nonumbers ///
					nogaps ///
					stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
					nonotes ///
					addnotes("Notes: 95% confidence intervals are under point estimates.") ///
					append	
				eststo clear
			}



	***  Regressions / Hypothesis tests
			
			
		/*****************************************************************************
		5.6: Hypothesis tests of mobile ownership and demographic details of individuals
		*****************************************************************************/
		
			* Pooled
			
			local depvar mobile_fm1
			local tabletitle "Owns mobile phone"
			eststo clear	
			loc option append
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress `depvar' `var' 
					gen sample = e(sample)
					count if (`depvar' ==.d | `depvar'==.r) 
					loc miss = r(N)
					count if (`depvar' ==.e)
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean `depvar'
					loc y1 = _b[`depvar']
					eststo: svy: regress `depvar' `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
				local k = `i' + 1
			esttab using "5_Mobile.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 5.6.1 Hypothesis tests of differences in mobile phone ownership among respondents from different vulnerable communities [All three states]") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///		
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"We test the null hypotheses that there are no differences in mobile phone ownership between vulnerable respondents and other respondents, with vulnerability being proxied by each of the categories above. Each column presents coefficients from a regression of the outcome variable on a dummy variable for the corresponding category and a constant. Hence we separately examine whether each individual type above has a different likelihood of owning a mobile phone compared to all other individuals (i.e. all those not in the specified type).")	///
					`option'
					loc option append
			
			
			* By state
			
			local depvar mobile_fm1
			local tabletitle "Owns mobile phone"
			eststo clear	
			tokenize `" "Andhra Pradesh" "Rajasthan" "West Bengal" "'
			loc option append
			forv i = 1/3{
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress `depvar' `var' if state == `i'
					gen sample = e(sample)
					count if (`depvar' ==.d | `depvar'==.r) & state == `i'
					loc miss = r(N)
					count if (`depvar' ==.e) & state == `i'
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean `depvar'
					loc y1 = _b[`depvar']
					eststo: svy: regress `depvar' `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
				local k = `i' + 1
			esttab using "5_Mobile.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 5.6.`k' Hypothesis tests of differences in mobile phone ownership among respondents from different vulnerable communities [State: ``i++'']") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///	
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"See footnote to Table 5.6.1 for a description of the hypotheses tested here.")	///
					`option'
					loc option append
			}
			
		
		/*****************************************************************************
		5.7: Hypothesis tests of Aadhaar seeding of mobile and demographic details of individuals
		*****************************************************************************/

			* Pooled
			
			local depvar mobile_aadhaar3
			local tabletitle "Seeding mobile phone to Aadhaar"
			eststo clear	
			loc option append
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress `depvar' `var'
					gen sample = e(sample)
					count if (`depvar' ==.d | `depvar'==.r) 
					loc miss = r(N)
					count if (`depvar' ==.e)
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean `depvar'
					loc y1 = _b[`depvar']
					eststo: svy: regress `depvar' `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
			esttab using "5_Mobile.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 5.7.1 Hypothesis tests of differences in Aadhaar seeding of mobile phone among respondents from different vulnerable communities [All three states]") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///		
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"We test the null hypotheses that there are no differences in the likelihood of seeding mobile phone with Aadhaar between vulnerable respondents and other respondents, with vulnerability being proxied by each of the categories above. Each column presents coefficients from a regression of the outcome variable on a dummy variable for the corresponding category and a constant. Hence we separately examine whether each individual type above has a different likelihood of seeding mobile phone with Aadhaar compared to all other individuals (i.e. all those not in the specified type).")	///
					append ///
					`option'
					loc option append
			
			* By state
			
			local depvar mobile_aadhaar3
			local tabletitle "Seeding mobile phone to Aadhaar"
			eststo clear	
			tokenize `" "Andhra Pradesh" "Rajasthan" "West Bengal" "'
			loc option append
			forv i = 1/3{
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress `depvar' `var' if state == `i'
					gen sample = e(sample)
					count if (`depvar' ==.d | `depvar'==.r) & state == `i'
					loc miss = r(N)
					count if (`depvar' ==.e) & state == `i'
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean `depvar'
					loc y1 = _b[`depvar']
					eststo: svy: regress `depvar' `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
				local k = `i' + 1	
			esttab using "5_Mobile.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 5.7.`k' Hypothesis tests of differences in Aadhaar seeding of mobile phone among respondents from different vulnerable communities [State: ``i++'']") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///	
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"See footnote to Table 5.7.1 for a description of the hypotheses tested here.")	///
					append ///
					`option'
					loc option append
			}
			
			
		/*****************************************************************************
		5.8: Hypothesis tests of usage of Aadhaar as ID and demographic details of individuals
		*****************************************************************************/
			
			* Pooled
			
			local depvar ad_mobilesimhow2
			local tabletitle "Used Aadhaar as ID"
			eststo clear	
			loc option append
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress `depvar' `var' 
					gen sample = e(sample)
					count if (`depvar' ==.d | `depvar'==.r) 
					loc miss = r(N)
					count if (`depvar' ==.e) 
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean `depvar'
					loc y1 = _b[`depvar']
					eststo: svy: regress `depvar' `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
			esttab using "5_Mobile.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 5.8.1 Hypothesis tests of differences in usage of Aadhaar as ID for mobile SIM purchases among respondents from different vulnerable communities (among those who have a mobile phone) [All three states]") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///		
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"We test the null hypotheses that there are no differences in usage of Aadhaar as ID for mobile SIM purchases between vulnerable respondents and other respondents, with vulnerability being proxied by each of the categories above. Each column presents coefficients from a regression of the outcome variable on a dummy variable for the corresponding category and a constant. Hence we separately examine whether each individual type above has a different likelihood of using Aadhaar as ID in mobile SIM purchases compared to all other individuals (i.e. all those not in the specified type).")	///
					append ///
					`option'
					loc option append
			
			* By state
			
			local depvar ad_mobilesimhow2
			local tabletitle "Used Aadhaar as ID"
			eststo clear	
			tokenize `" "Andhra Pradesh" "Rajasthan" "West Bengal" "'
			loc option append
			forv i = 1/3{
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress `depvar' `var' if state == `i'
					gen sample = e(sample)
					count if (`depvar' ==.d | `depvar'==.r) & state == `i'
					loc miss = r(N)
					count if (`depvar' ==.e) & state == `i'
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean `depvar'
					loc y1 = _b[`depvar']
					eststo: svy: regress `depvar' `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
				local k = `i' + 1	
			esttab using "5_Mobile.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 5.8.`k' Hypothesis tests of differences in usage of Aadhaar as ID for mobile SIM purchases among respondents from different vulnerable communities (among those who have a mobile phone) [State: ``i++'']") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///	
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"See footnote to Table 5.8.1 for a description of the hypotheses tested here.")	///
					append ///
					`option'
					loc option append
			}
		
		
		/*****************************************************************************
		5.9: Hypothesis tests of usage of Aadhaar e-KYC and demographic details of individuals
		*****************************************************************************/

			* Pooled
			
			local depvar ad_mobilesimhow3
			local tabletitle "Used Aadhaar e-KYC"
			eststo clear	
			loc option append
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress `depvar' `var' if pre_ekyc==0
					gen sample = e(sample)
					count if (`depvar' ==.d | `depvar'==.r) & pre_ekyc==0
					loc miss = r(N)
					count if (`depvar' ==.e) & pre_ekyc==0
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean `depvar'
					loc y1 = _b[`depvar']
					eststo: svy: regress `depvar' `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
				
				esttab using "5_Mobile.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 5.9.1 Hypothesis tests of differences in usage of Aadhaar e-KYC in SIM card purchases among respondents from different vulnerable communities (among those who have a mobile phone and those who got their SIM card ) [All three states]") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///		
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"We test the null hypotheses that there are no differences in usage of Aadhaar e-KYC for mobile SIM purchases between vulnerable respondents and other respondents, with vulnerability being proxied by each of the categories above. Each column presents coefficients from a regression of the outcome variable on a dummy variable for the corresponding category and a constant. Hence we separately examine whether each individual type above has a different likelihood of using Aadhaar e-KYC in mobile SIM purchases compared to all other individuals (i.e. all those not in the specified type).")	///
					append ///
					`option'
					loc option append
			
			* By state
			
			local depvar ad_mobilesimhow3
			local tabletitle "Used Aadhaar e-KYC"
			eststo clear	
			tokenize `" "Andhra Pradesh" "Rajasthan" "West Bengal" "'
			loc option append
			forv i = 1/3{
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress `depvar' `var' if state == `i' & pre_ekyc==0
					gen sample = e(sample)
					count if (`depvar' ==.d | `depvar'==.r) & state == `i' & pre_ekyc==0
					loc miss = r(N)
					count if (`depvar' ==.e) & state == `i' & pre_ekyc==0
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean `depvar'
					loc y1 = _b[`depvar']
					eststo: svy: regress `depvar' `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
				local k = `i' + 1
				
				esttab using "5_Mobile.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 5.9.`k' Hypothesis tests of differences in usage of Aadhaar e-KYC in SIM card purchases among respondents from different vulnerable communities (among those who have a mobile phone and those who got their SIM card ) [State: ``i++'']") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'" "`tabletitle'") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///		
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"See footnote to Table 5.9.1 for a description of the hypotheses tested here.")	///
					append ///
					`option'
					loc option append
				}
			
			
		/*****************************************************************************
		5.10: Hypothesis tests of difference of having mobile SIM activated in 1 day by the usage of Aadhaar e-KYC
		*****************************************************************************/
		
			local depvar simactivatecategories1
			local tabletitle "SIM activated in 1 day"
			local var ad_mobilesimhow3
			eststo clear
			
			* Pooled
			
				qui svy: regress `depvar' `var' if pre_ekyc==0
				gen sample = e(sample)
				count if (`depvar' ==.d | `depvar' ==.r) & pre_ekyc==0
				loc miss = r(N)
				count if (`depvar' ==.e) & pre_ekyc==0
				loc errors = r(N)
				
				preserve
				keep if sample == 1
				svy: mean `var'
				loc x1 = _b[`var']
				svy: mean `depvar'
				loc y1 = _b[`depvar']
				eststo: svy: regress `depvar' `var'
				estadd scalar missing = `miss'
				estadd scalar errors = `errors'
				estadd scalar y = `y1'
				estadd scalar x = `x1'
				restore
				drop sample
				
			* By state
			
			forvalues i=1/3{
				qui svy: regress `depvar' `var' if state==`i' & pre_ekyc==0
				gen sample = e(sample)
				count if (`depvar'==.d | `depvar'==.r) & state==`i' & pre_ekyc==0
				loc miss = r(N)
				count if (`depvar'==.e) & state==`i' & pre_ekyc==0
				loc errors = r(N)
				preserve
				keep if sample == 1
				svy: mean `var'
				loc x1 = _b[`var']
				svy: mean `depvar'
				loc y1 = _b[`depvar']
				eststo: svy: regress `depvar' `var'
				estadd scalar missing = `miss'
				estadd scalar errors = `errors'
				estadd scalar y = `y1'
				estadd scalar x = `x1'
				restore
				drop sample
			}
			esttab using "5_Mobile.rtf", ///
				compress ///
				eqlabels(none) ///
				label ///
				title ("Table 5.10 Hypothesis tests of differences in likelihood of having mobile SIM activated in 1 day by usage of Aadhaar e-KYC (among those who have a mobile phone and those who got their SIM card )") ///	
				mtitles("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				p ///
				star (* 0.1 ** 0.05 *** 0.01) ///
				lines ///
				b (3) ///
				p (2) ///
				nogaps ///
				stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///
				nonotes ///
				addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
				"We test the null hypothesis that there is no difference in the likelihood of having mobile SIM activated in 1 day between respondents who used Aadhaar e-KYC in mobile SIM purchases and other respondents. (We discuss this result on p30 of the State of Aadhaar Report 2017-18.)")	///
				append
